package com.bl.weilan.manager.controller.train;

import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.TeacherTrainEntity;
import com.bl.weilan.dao.model.TrainEntity;
import com.bl.weilan.manager.controller.BaseController;
import com.bl.weilan.service.biz.train.TrainService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.train.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/train"})
@Api(value = "培训相关", description = "培训相关api")
public class TrainController extends BaseController {
    @Autowired
    TrainService trainService;

    @ApiOperation(value = "获取培训列表信息", notes = "获取培训列表信息")
    @ApiImplicitParams({
             @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_train_list"})
    public ApiResponseBody<TrainListVo> trainList(
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        TrainListVo trainListVo = trainService.getTrainLists(pageable, null);

        return ApiResponseBody.createSuccessBody(trainListVo);
    }

    @ApiOperation(value = "获取一条培训详情信息", notes = "获取一条培训")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_train_byid"})
    public ApiResponseBody<TrainListVo> trainList(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        TrainEntity trainEntity = trainService.getTrainById(id);

        return ApiResponseBody.createSuccessBody(trainEntity);
    }

    @ApiOperation(value = "增加培训信息，闻", notes = "增加培训信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add_train"})
    public ApiResponseBody add(
            @Valid @RequestBody TrainAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        trainService.addTrain(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量", notes = "删除批量 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        trainService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除一条培训信息", notes = "删除单个培训信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        trainService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "修改培训信息", notes = "修改培训信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody TrainModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        trainService.modify(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "修改专家培训信息", notes = "修改专家培训信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify_teacher"})
    public ApiResponseBody modifyTeacher(
            @Valid @RequestBody TeacherTrainModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        trainService.modTeacherTrain(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "增加专家培训信息", notes = "增加专家培训信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add_teacher"})
    public ApiResponseBody addTeacher(
            @Valid @RequestBody TeacherTrainAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        trainService.addTeacherTrain(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除一条专家培训", notes = "删除专家培训 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_teacher"})
    public ApiResponseBody del(
            BindingResult result,
            HttpServletRequest request) {


        trainService.delTeacherTrain();

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "获取一条专家培训详情信息", notes = "获取一条专家培训")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_teacher"})
    public ApiResponseBody<TeacherTrainEntity> teacherTrainList(
            HttpServletRequest request) {

        TeacherTrainEntity trainEntity = trainService.getTeacherTrain();

        return ApiResponseBody.createSuccessBody(trainEntity);
    }
}
